#!/bin/sh
#
# This is the script for generating files for a specific Dalton test job.
#
# For the .check file ksh or bash is preferred, otherwise use sh
# (and hope it is not the old Bourne shell, which will not work)
#
if [ -x /bin/ksh ]; then
   CHECK_SHELL='#!/bin/ksh'
elif [ -x /bin/bash ]; then
   CHECK_SHELL='#!/bin/bash'
else
   CHECK_SHELL='#!/bin/sh'
fi


#######################################################################
#  TEST DESCRIPTION
#######################################################################
cat > cc_rsp_alpha2.info <<'%EOF%'
   cc_rsp_alpha2
   -------------
   Molecule:         Ne atom in D2h
   Wave Function:    CCS, CC2, CCSD / d-aug-cc-pVDZ
   Test Purpose:     Frequency-dependent polarizabilities and
                     dispersion coefficients
%EOF%

#######################################################################
#  INTEGRAL INPUT
#######################################################################
cat > cc_rsp_alpha2.mol <<'%EOF%'
BASIS
d-aug-cc-pVDZ
Neon atom
small test basis
    1    3  Y  X  Z   1.00D-15
       10.0   1
Ne    0.0000000000000000  0.0000000000000000 0.00000000000000000
%EOF%

#######################################################################
#  DALTON INPUT
#######################################################################
cat > cc_rsp_alpha2.dal <<'%EOF%'
**DALTON INPUT
.RUN WAVE FUNCTIONS
**INTEGRAL
.DIPLEN
**WAVE FUNCTIONS
.TITLE
  linear polarizability for the Ne atom
  for CCS, CC2 and CCSD wavefunctions
.CC
*SCF INPUT 
.THRESH
 1.0d-12
*CC INPUT 
.CCS
.CC2
.CCSD
.THRENR
 1.0d-10
.THRLEQ
 1.0d-10
.PRINT
  1
.NSYM
  8
.FROIMP
 1 0 0 0 0 0 0 0
 0 0 0 0 0 0 0 0
*CCLR
.OLD_LR
.OPERATOR
ZDIPLEN ZDIPLEN
.FREQUENCIES
  2
0.04282270  0.06562487
.DISPCF
  4
**END OF DALTON INPUT
%EOF%
#######################################################################

 

#######################################################################

#######################################################################
#  CHECK SCRIPT
#######################################################################
echo $CHECK_SHELL >cc_rsp_alpha2.check
cat >>cc_rsp_alpha2.check <<'%EOF%'
log=$1

if [ `uname` = Linux ]; then
   GREP="egrep -a"
else
   GREP="egrep"
fi

if $GREP -q "not implemented for parallel calculations" $log; then
   echo "TEST ENDED AS EXPECTED"
   exit 0
fi

# SCF, MP2 and CCSD energies:
CRIT1=`$GREP "Total SCF   energy:                  \-128.49636440" $log | wc -l`
CRIT2=`$GREP "Total MP2   energy:                  \-128.70354558" $log | wc -l`
CRIT3=`$GREP "Total CCSD  energy:                  \-128.70680679" $log | wc -l`
TESTA=`expr $CRIT1 \+ $CRIT2 \+ $CRIT3` 
CTRLA=9
ERRORA="ENERGIES NOT CORRECT"


# CCSD polarizabilities
CRIT1=`$GREP "<<ZDIPLEN ,ZDIPLEN >>\( ( |0)\.042823\) =    \-2.7118560" $log | wc -l`
CRIT2=`$GREP "<<ZDIPLEN ,ZDIPLEN >>\( ( |0)\.065625\) =    \-2.7191445" $log | wc -l`
TESTB=`expr $CRIT1 \+ $CRIT2`
CTRLB=2
ERRORB="CCSD POLARIZABILITIES NOT CORRECT"


# CCSD dispersion coefficients
CRIT1=`$GREP "ZDIPLEN     ZDIPLEN      \-4        109.7683811" $log | wc -l`
CRIT2=`$GREP "                         \-2        7.682879049" $log | wc -l`
CRIT3=`$GREP "                          0        2.70649113" $log | wc -l`
CRIT4=`$GREP "                          2        2.9163958"  $log | wc -l`
CRIT5=`$GREP "                          4        4.997054"   $log | wc -l`
TESTC=`expr $CRIT1 \+ $CRIT2 \+ $CRIT3 \+ $CRIT4 \+ $CRIT5` 
CTRLC=5
ERRORC="CCSD DISPERSION COEFFICIENTS NOT CORRECT"


TESTSUM=`expr $TESTA \+ $TESTB \+ $TESTC`
CTRLSUM=`expr $CTRLA \+ $CTRLB \+ $CTRLC`

if [ $TESTSUM -eq $CTRLSUM ]
then
  echo TEST ENDED PROPERLY
else

  if [ $TESTA -ne $CTRLA ]; then
    echo $ERRORA
  fi

  if [ $TESTB -ne $CTRLB ]; then
    echo $ERRORB
  fi

  if [ $TESTC -ne $CTRLC ]; then
    echo $ERRORC
  fi

  echo THERE IS A PROBLEM 
  exit 1

fi

exit 0

%EOF%
chmod +x cc_rsp_alpha2.check
#######################################################################
